<{include file="Public/top.html" }>
</head>
<body>
<div id="warpper" style="height: 900px;">
    <div class="content" style="height: 900px;">
        <div class="location">套餐管理</div>
        <{include file= "Business/nav.html"}>

        <div class="topic">套餐信息</div>
        <div class="form-box border0 border-box">
            <form action="<{u($smarty.const.ACTION_NAME)}>" class="ui-form" method="post" id="addManagerForm">
                <input type="hidden" name="id" value="<{$obj.id}>"/>
                <div class="ui-form-item">
                    <label class="ui-label">所属商家：</label>
                    <select name="restaurantId" id="restaurantId" class="ui-select" style="width:200px;">
                        <{foreach from=$restaurant item=one}>
                            <option value="<{$one['id']}>" <{if $one['id'] eq $obj.restaurantId}>selected <{/if}>><{$one['restaurantName']}></option>>
                        <{/foreach}>
                    </select>
                    <select name="storeId" id="storeId" class="ui-select" style="width:200px;">
                        <{if $obj.storeId}>
                            <option value="<{$obj.storeId}>"><{$storeName}></option>
                        <{/if}>
                    </select>
                </div>

                <div class="ui-form-item">
                    <label class="ui-label">套餐名称：</label>
                    <input type="text" class="ui-text" name="title" value="<{$obj.title}>" required/>
                </div>

                <div class="ui-form-item">
                    <label class="ui-label">套餐图片：</label>
                    <span class="picture_box picture_150 " id="listPic" >
                        <div class="a-imgBox" id="imgBox" <{if $obj.listPic}> style="display:block;"<{else}>style="display:none;"<{/if}>>
                            <input type="hidden" name="listPic" value="<{$preUploadUrl}><{$obj.listPic}>">
                            <a href="javascript:void(0);" class="a-close" onclick="deleteListPic()"></a>
                            <img src="<{$preUploadUrl}><{$obj.listPic}>" width="150" height="130" />
                        </div>
                        <div>
                            <a href="javascript:;" class="a-upload">
                                <input type="file" name="file"  >
                            </a>
                            <i>上传图片</i>
                            <i>150*130</i>
                        </div>
                    </span>
                </div>


                <div class="ui-form-item ">
                    <label class="ui-label">原价：</label>
                    <input type="text" class="ui-text" name="priceOriginal" value="<{$obj.priceOriginal}>" required="required" />
                </div>

                <div class="ui-form-item">
                    <label class="ui-label">优惠价：</label>
                    <input type="text" class="ui-text" name="pricePresent" value="<{$obj.pricePresent}>" required="required" />
                </div>

        <div class="ui-form-item">
            <label class="ui-label">显示顺序：</label>
            <input type="number" min="1" max="127" class="ui-text" name="showOrder" value="<{$obj.showOrder}>" /> 从大到小排序
        </div>

        <div class="ui-form-item">
            <label class="ui-label">简单描述：</label>
            <input type="text" class="ui-text" name="summary" value="<{$obj.summary}>" maxlength="200" placeholder="一句话简要描述" required/>
        </div>
        <div class="ui-form-item">
            <label class="ui-label">跳转地址：</label>
            <input type="text" id="jumpURL" class="ui-text" name="jumpURL" value="<{$obj.jumpURL}>" maxlength="200" style="width: 60%;"  />
        </div>



        <div  class="ui-form-item uploader detailmore" style="min-height: 157px; <{if strlen($obj.jumpURL) gt 1}>display:none<{/if}> ">
            <label class="ui-label">套餐图集:</label>
            <div style="width: 775px;display: inline-block;">
                <{foreach from=$album item=img}>
                    <{if $img}>
                    <span class="picture_box picture_150">
                        <div class="a-imgBox"   style="display:block;">
                            <a href="javascript:void(0);" class="a-close" onclick="removeElement(this)"></a>
                            <img src="<{$preUploadUrl}><{$img}>" width="150" height="130" />
                            <input type="hidden" name="album[]" value="<{$img}>" />
                        </div>
                    </span>
                <{/if}>
                <{/foreach}>

                    <span class="picture_box picture_150 " id="addImg" style="position: absolute;">
                        <div>
                            <a href="javascript:;" class="a-upload">
                                <input type="file" name="file"  >
                            </a>
                            <i>上传图片</i>
                            <i>150*130</i>
                        </div>
                    </span>
            </div>

        </div>

        <div class="reply_box detailmore" style="<{if strlen($obj.jumpURL) gt 1}>display:none<{/if}>">
            <label class="ui-label">套餐说明：</label>
            <textarea id="editor" name="content" class="edui-default inline-block"><{$obj.content}></textarea>
        </div>

                <div class="integral_btn-group">
                    <input type="submit" value="提交" class="ui-button"/>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<{include file="Public/foot.html" }>
<{include file="Public/ueditor.html" }>
<script>


    //删除图片
    function deleteListPic() {
        $('#imgBox').hide();
        $('.uptxt').text('上传图片');
        $('#listPic').val('');
    }


    (function ($) {
        'use strict';
        $.fn.uploader = function () {
            return this.each(function () {
                var $this = $(this);
                var $img = $this.find('img');
                var $file = $this.find('input[type=file]');
                var $hidden = $this.find('input[type=hidden]');
                var $txt = $this.find('i.uptxt');
                $file.AjaxFileUpload({
                    action: './api.php?m=Api&c=index&a=ajaxUpload&from=IMG_PACKAGE_ALBUM',
                    onSubmit: function () {
                        $txt.text('上传中');
                    },
                    onComplete: function (filename, response) {
                        if(parseInt(response.id)>0){
                            $txt.text("上传成功");
                            newImg(response.msg);
                        }else{
                            $txt.text(response.msg);
                        }
                    }
                });
            });
        }
    })(jQuery);
    $('#addImg').uploader();


    (function ($) {
        'use strict';
        $.fn.uploader = function () {
            return this.each(function () {
                var $this = $(this);
                var $img = $this.find('img');
                var $file = $this.find('input[type=file]');
                var $hidden = $this.find('input[type=hidden]');
                var $txt = $this.find('i.uptxt');
                var $imgBox = $this.find('div[id=imgBox]');
                $file.AjaxFileUpload({
                    action: './api.php?m=Api&c=index&a=ajaxUpload&from=IMG_PACKAGE_LIST',
                    onSubmit: function () {
                        $txt.text('上传中');
                    },
                    onComplete: function (filename, response) {
                        if(parseInt(response.id)>0){
                            $txt.text("上传成功");
                            $hidden.attr('value', response.msg);
                            $img.attr("src",response.msg);
                            $imgBox.css('display','block');
                        }else{
                            $txt.text(response.msg);
                        }

                    }
                });
            });
        }
    })(jQuery);
    $('#listPic').uploader();

    function removeElement(obj){
        $(obj).parents('.picture_150').remove();
    }

    function newImg(src){
        $img=$('<span class="picture_box picture_150"><div class="a-imgBox"  style="display:block;"><a href="javascript:void(0);" class="a-close" onclick="removeElement(this)"></a><img src="<{$preUploadUrl}><{$img}>" width="150" height="130" /> <input type="hidden" name="album[]" value="" /></div></span>');
        $('#addImg').before($img);
        $img.find('input[type=hidden]').val(src);
        $img.find('img').attr('src',src);
    }

    $(document).ready(
            function(){
                $('#restaurantId').on('change',function(){
                    var restaurantId=$('#restaurantId').val();
                    $.getJSON("./api.php?m=Api&c=Business&a=getStoreListByRestaurantId",{id:restaurantId,partner:1},function(data){
                        if(data){
                            var $store=$("#storeId");
                            $store.empty();
                            $.each(data.data,function(i,item){
                                $store.prepend("<option value='" + item.id + "'>" + item.storeName + "</option>");
                            });
                        }
                    });
                });

                $('#jumpURL').on('keyup',function(){
                    if($('#jumpURL').val().length>0){
                        $('.detailmore').hide();
                    }else{
                        $('.detailmore').show();
                    }
                });
            }

    );
</script>